define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_agent_credit(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"credit_line":1000,"debt_total":200,"store_name":"世达","advance": 15200.50},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		//返回信息
		return {
			//欠款详情
			agent_credit: function(store_id,type,callback) {	
				Http.post({
					method: 'member.supplier.credit.detail',
					store_id: store_id,
					type:type
				}, function(result) {
					if(callback)
						callback(get_data_agent_credit(result).result);
				}, function(e) {

				}, function() {

				})
			},
			//还款。userType 默认0：供应商，1：好友店铺
			credit_repay: function(store_id, money, type, photo, payPass,bankObj,userType,callback) {
				var voucher = new Object();
				voucher.photo = photo;
				voucher.type = type;
				voucher.payPass = payPass;
				if(bankObj){
					voucher.bank_id = bankObj.bank_id;
					voucher.receiver_name = bankObj.receiver_name;
					voucher.bank_name = bankObj.bank_name;
					voucher.bank_account = bankObj.bank_account;
				}
				voucher = JSON.stringify(voucher);
				Http.post({
					method: 'member.supplier.credit.repay',
					store_id: store_id,
					money: money,
					type:userType,
					voucher: voucher
				}, function(result) {
					if(callback)
						callback(result);
				}, function(e) {

				}, function() {

				})
			}

		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Confirm_payment", factory);
});